﻿Imports Infragistics.Win.UltraWinGrid

Public Class KeToanNganHang1
    'state : 0 mặc định - trạng thái 1- tạo mới 2 sửa 3 - xóa
    Private state As Integer
    'load form
    Dim isLoad As Boolean = True
    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = (Keys.Control Or Keys.N) Then
            Return getTaoMoi()
        End If
        If keyData = (Keys.Control Or Keys.S) Then
            Return getLuu()
        End If
        If keyData = (Keys.Control Or Keys.E) Then
            Return getSua()
        End If
        If keyData = (Keys.Control Or Keys.D) Then
            Return Me.KetoantienmatIUltraGrid_ThongTin.getXoa()
        End If
        If keyData = (Keys.Control Or Keys.P) Then
            'Return Me.getIn()
        End If
        If keyData = (Keys.Control Or Keys.R) Then
            Return Me.KetoantienmatIUltraGrid_ThongTin.getRefresh()
        End If
        If (keyData = (Keys.Control Or Keys.Q)) Then
            Return getThoat()
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
    Private Sub loadDuLieu()
        If isLoad Then
            Me.Cursor = Cursors.WaitCursor
            Me.DmnganhangTableAdapter.Fill(Me.ErpharmaDataSet.dmnganhang)
            Me.KetoannganhangTableAdapter.Fill(Me.ErpharmaDataSet.ketoannganhang)
            Me.Ketoannganhang_thongtinthueTableAdapter.Fill(Me.ErpharmaDataSet.ketoannganhang_thongtinthue)
            Me.Ketoannganhang_thongtinchinhTableAdapter.Fill(Me.ErpharmaDataSet.ketoannganhang_thongtinchinh)
            Me.KetoannganhangTableAdapter.Fill(Me.ErpharmaDataSet.ketoannganhang)
            Me.DmkhoanmucphiTableAdapter.Fill(Me.ErpharmaDataSet.dmkhoanmucphi)
            Me.DmnghiepvuTableAdapter.Fill(Me.ErpharmaDataSet.dmnghiepvu)
            Me.DmnhanvienTableAdapter.Fill(Me.ErpharmaDataSet.dmnhanvien)
            Me.DmphongbanTableAdapter.Fill(Me.ErpharmaDataSet.dmphongban)
            Me.DmloaitienTableAdapter.Fill(Me.ErpharmaDataSet.dmloaitien)
            Me.DmkhachhangTableAdapter.Fill(Me.ErpharmaDataSet.dmkhachhang)
            Me.DmtinhtrangphieuTableAdapter.Fill(Me.ErpharmaDataSet.dmtinhtrangphieu)
            Me.Dmtaikhoancap2TableAdapter.Fill(Me.ErpharmaDataSet.dmtaikhoancap2)
            'set giao diện
            Me.KetoantienmatIUltraGrid_ThongTin.setGiaoDien_Doi_ThongTin()
            Me.KetoantienmatIUltraGrid_DanhSach.setGiaoDienTuyBien()
            Me.DmnghiepvuIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.DmnhanvienIUltraDropDown.setGiaoDien()
            Me.DmphongbanIUltraDropDown.setGiaoDien()
            Me.DmloaitienIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.DmkhachhangIUltraDropDown.setGiaoDien()
            Me.DmtinhtrangphieuIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setGiaoDienTuyBien()
            Me.Ketoantienmat_thongtinthueIUltraGrid.setGiaoDienTuyBien()
            Me.DmnganhangIUltraDropDown.setGiaoDien()
            Me.Dmtaikhoancap2IUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.Dmtaikhoancap2IUltraDropDown1.setGiaoDien_An_ColumnHeader()
            Me.DmkhoanmucphiIUltraDropDown.setGiaoDien_An_ColumnHeader()

            'danh sách
            Me.KetoantienmatIUltraGrid_DanhSach.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoannganhang, Me.KetoannganhangBindingSource, Me.KetoannganhangTableAdapter, Me.ErpharmaDataSet)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnghiepvuIUltraDropDown, Me.ErpharmaDataSet.dmnghiepvu)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnhanvienIUltraDropDown, Me.ErpharmaDataSet.dmnhanvien)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnganhangIUltraDropDown, Me.ErpharmaDataSet.dmnganhang)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmtinhtrangphieuIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrangphieu)
            Me.KetoantienmatIUltraGrid_DanhSach.setTimKiemTrenCotUltraGrid()
            KetoantienmatIUltraGrid_DanhSach.setSummaries("nguyente")
            KetoantienmatIUltraGrid_DanhSach.setSummaries("tienvnd")
            'thông tin
            Me.KetoantienmatIUltraGrid_ThongTin.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoannganhang, Me.KetoannganhangBindingSource, Me.KetoannganhangTableAdapter, Me.ErpharmaDataSet)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnghiepvuIUltraDropDown, Me.ErpharmaDataSet.dmnghiepvu)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnhanvienIUltraDropDown, Me.ErpharmaDataSet.dmnhanvien)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnganhangIUltraDropDown, Me.ErpharmaDataSet.dmnganhang)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmtinhtrangphieuIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrangphieu)
            'gán mặc định
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("loaitien", "VND")
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("tygia", 1)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("nguyente", 0)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("tienvnd", 0)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("sochungtu", "")
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ngaylap", Today)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ngaylapthamchieu", Today)
            'bắt lỗi
            'set cot bat loi
            Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("nghiepvu")
            'Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("donvi")
            Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("tinhtrang")
            'thông tin chính
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoannganhang_thongtinchinh, Me.Ketoannganhang_thongtinchinhBindingSource, Me.Ketoannganhang_thongtinchinhTableAdapter, Me.ErpharmaDataSet)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.Dmtaikhoancap2IUltraDropDown, Me.ErpharmaDataSet.dmtaikhoancap2)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.Dmtaikhoancap2IUltraDropDown1, Me.ErpharmaDataSet.dmtaikhoancap2)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.DmkhoanmucphiIUltraDropDown, Me.ErpharmaDataSet.dmkhoanmucphi)
            Ketoantienmat_thongtinchinhIUltraGrid.setChoPhepMenuStrip()
            Ketoantienmat_thongtinchinhIUltraGrid.setTimKiemTrenCotUltraGrid()

            'mặc định
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("nguyente", 0)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("tienvnd", 0)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("ngay", Today)
            'summaries thông tin chính
            'thêm tổng summaries
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setSummaries("nguyente")
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setSummaries("tienvnd")
            'thêm tổng summaries
            Me.Ketoantienmat_thongtinthueIUltraGrid.setSummaries("doanhthu")
            Me.Ketoantienmat_thongtinthueIUltraGrid.setSummaries("thue")
            Me.Ketoantienmat_thongtinthueIUltraGrid.setSummaries("tongcong")
            'thông tin khai thuế
            Me.Ketoantienmat_thongtinthueIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoannganhang_thongtinthue, Me.Ketoannganhang_thongtinthueBindingSource, Me.Ketoannganhang_thongtinthueTableAdapter, Me.ErpharmaDataSet)
            Me.Ketoantienmat_thongtinthueIUltraGrid.setChoPhepMenuStrip()
            Me.Ketoantienmat_thongtinthueIUltraGrid.setTimKiemTrenCotUltraGrid()
            'Me.KetoannganhangBindingSource.MoveLast()
            'If KetoantienmatIUltraGrid_ThongTin.Rows.Count > 0 Then
            '    KetoantienmatIUltraGrid_ThongTin.ActiveRowScrollRegion.ScrollRowIntoView(Me.KetoantienmatIUltraGrid_ThongTin.Rows(Me.KetoantienmatIUltraGrid_ThongTin.Rows.Count - 1))
            'End If
            Me.KetoantienmatIUltraGrid_ThongTin.setMoveLast()
            ThongTinChinh_TimKiemIUltraGrid.setGiaoDienTuyBien()
            ThongTinThue_TimKiemIUltraGrid.setGiaoDienTuyBien()
            ThongTinChinh_TimKiemIUltraGrid.setReadonly(True)
            ThongTinThue_TimKiemIUltraGrid.setReadonly(True)
            Me.ThongTinChinh_TimKiemIUltraGrid.setGroupBy("ma")
            Me.ThongTinThue_TimKiemIUltraGrid.setGroupBy("ma")
            ThongTinChinh_TimKiemIUltraGrid.setTimKiemTrenCotUltraGrid()
            ThongTinThue_TimKiemIUltraGrid.setTimKiemTrenCotUltraGrid()
            Me.setReadOnly(True)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setTimKiemTheoShift()
            Me.Cursor = Cursors.Default
            'load.Close()
            Me.isLoad = False
        End If
    End Sub
    Private Sub KeToanTienMat1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub
    'để cho lưới readonly
    Private Sub setReadOnly(ByVal isTrue As Boolean)
        Me.KetoantienmatIUltraGrid_ThongTin.setReadonly(isTrue)
        Me.Ketoantienmat_thongtinchinhIUltraGrid.setReadonly(isTrue)
        Me.Ketoantienmat_thongtinthueIUltraGrid.setReadonly(isTrue)
        Me.KetoantienmatIUltraGrid_DanhSach.setReadonly(isTrue)
    End Sub
    Private Function getTaoMoi()
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ma", getMa)
        If (Me.KetoantienmatIUltraGrid_ThongTin.getTaoMoi()) Then
            Me.setReadOnly(False)
            Me.state = 1
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnTaoMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTaoMoi.Click
        Me.getTaoMoi()
    End Sub
    Private Function getLuu()
        Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nguyente").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("nguyente").Value
        Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tienvnd").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("tienvnd").Value
        If Me.KetoantienmatIUltraGrid_ThongTin.getLuu() Or Me.Ketoantienmat_thongtinchinhIUltraGrid.getLuuNgam() Or Me.Ketoantienmat_thongtinthueIUltraGrid.getLuuNgam() Then
            Me.setReadOnly(True)
            Me.state = 0
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLuu.Click
        Me.getLuu()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Me.getSua()
    End Sub
    Private Function getSua()
        If KetoantienmatIUltraGrid_ThongTin.getSua() And Me.Ketoantienmat_thongtinchinhIUltraGrid.getSua And Me.Ketoantienmat_thongtinthueIUltraGrid.getSua Then
            Me.setReadOnly(False)
            Me.state = 2
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        KetoantienmatIUltraGrid_ThongTin.getXoa()
    End Sub

    Private Sub btnLamTuoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamTuoi.Click
        Me.KetoantienmatIUltraGrid_ThongTin.getRefresh()
    End Sub

    Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click
        'Me.Ketoantienmat_thongtinthueIUltraGrid.DisplayLayout.Bands(0).AddNew()
        'Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ma").Value = Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("ma").Value
    End Sub
    Private Function getThoat()
        If Me.KetoantienmatIUltraGrid_ThongTin.getCoThayDoiDuLieuKhong Or Me.Ketoantienmat_thongtinchinhIUltraGrid.getCoThayDoiDuLieuKhong Or Me.Ketoantienmat_thongtinthueIUltraGrid.getCoThayDoiDuLieuKhong Then
            If KetoantienmatIUltraGrid_ThongTin.getLuu Then
                Ketoantienmat_thongtinchinhIUltraGrid.getLuuNgam()
                Ketoantienmat_thongtinthueIUltraGrid.getLuuNgam()
            End If
            Return True
        Else
            Me.Dispose()
            Me.Close()
            Return True
        End If
    End Function
    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.getThoat()
    End Sub
    'mã tự động của phiếu
    Private Function getMa() As String
        'Try
        '    Dim ma As String = Me.HttientoTableAdapter.getMaKeToanNganHang(New Date(2012, 4, 1), New Date(2012, 4, 30))
        '    Return ma
        'Catch ex As Exception
        '    Return Today.Year & Today.Month & Today.Day
        'End Try
        Return ""
    End Function

    Private Sub KetoantienmatIUltraGrid_ThongTin_AfterCellListCloseUp(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles KetoantienmatIUltraGrid_ThongTin.AfterCellListCloseUp
        Try
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nghiepvu").IsActiveCell Then
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("taikhoanno", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanno").Value)
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("taikhoanco", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanco").Value)
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("taikhoanvat", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanvat").Value)
            End If
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("bophan").IsActiveCell Then
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("phongban", Me.DmphongbanIUltraDropDown.ActiveRow.Cells("ma").Value)
            End If
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub KetoantienmatIUltraGrid_ThongTin_BeforeCellDeactivate(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles KetoantienmatIUltraGrid_ThongTin.BeforeCellDeactivate
        If Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nghiepvu").IsActiveCell Then
            Me.KetoantienmatIUltraGrid_ThongTin.getLuuNgam()
        End If
        If Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tinhtrang").IsActiveCell And (state = 2 Or state = 1) Then
            Me.KetoantienmatIUltraGrid_ThongTin.getLuuNgam()
            Me.KetoantienmatIUltraGrid_ThongTin.setFocusCellUltraGrid(Me.Ketoantienmat_thongtinchinhIUltraGrid)
        End If
    End Sub
    Private Sub tinhDong_ThongTinChinh()
        If Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("nguyente").IsActiveCell Then
            Try
                Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("tienvnd").Value = CDec(KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tygia").Value) * CDec(Me.Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("nguyente").Value)
            Catch ex As Exception
                Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("tienvnd").Value = 0
            End Try
        End If
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.AfterCellUpdate
        tinhDong_ThongTinChinh()
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.MouseEnter
        Me.loadDuLieu()
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_SummaryValueChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.SummaryValueChangedEventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.SummaryValueChanged
        'Try
        '    Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nguyente").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("nguyente").Value
        '    Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tienvnd").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("tienvnd").Value
        'Catch ex As Exception

        'End Try
    End Sub
    Private Sub tinhDong_ThongTinThue() 'tính doanh thu nếu gõ %thue
        If Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").IsActiveCell Then
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value) * CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value) / 100
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value) - CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value)
        End If
        If Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").IsActiveCell Then
            Dim thue As Decimal = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value)
            Dim tongcong As Decimal = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value)
            Dim phantramthue As Integer = Math.Round(thue / tongcong * 100, 0)
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = tongcong - thue
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value = phantramthue
        End If
    End Sub

    Private Sub ultraTabChiTiet_SelectedTabChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs) Handles ultraTabChiTiet.SelectedTabChanged
        Dim groupByRow As UltraGridGroupByRow
        If Me.ultraTabChiTiet.SelectedTab Is ultraTabChiTiet.Tabs("thongtinthue") Then
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setGroupBy("sohopdong")
            If Ketoantienmat_thongtinthueIUltraGrid.getCoThayDoiDuLieuKhong Then
                If MessageBox.Show("Bạn có muốn lấy dữ liệu sang thuế tự động hay không ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
                    For index = 0 To Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.ParentCollection.Count - 1
                        Try
                            Me.Ketoantienmat_thongtinthueIUltraGrid.DisplayLayout.Bands(0).AddNew()
                            groupByRow = Ketoantienmat_thongtinchinhIUltraGrid.Rows(index)
                            Dim sum As Double = groupByRow.Rows.SummaryValues("tienvnd").Value
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ma").Value = Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("ma").Value
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("donvi").Value = groupByRow.Rows(0).Cells("khachhang").Value
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("sohoadon").Value = groupByRow.Rows(0).Cells("sohopdong").Value
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ngayhoadon").Value = groupByRow.Rows(0).Cells("ngay").Value
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = sum
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value = 0
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value = 0
                            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value = sum
                        Catch ex As Exception

                        End Try
                    Next
                End If

            End If
        End If
        If Me.ultraTabChiTiet.SelectedTab Is ultraTabChiTiet.Tabs("thongtinchinh") Then
            Ketoantienmat_thongtinchinhIUltraGrid.setClearGroupBy()
        End If
    End Sub

    Private Sub Ketoantienmat_thongtinthueIUltraGrid_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles Ketoantienmat_thongtinthueIUltraGrid.AfterCellUpdate
        tinhDong_ThongTinThue()
    End Sub

    Private Sub KetoantienmatIUltraGrid_ThongTin_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles KetoantienmatIUltraGrid_ThongTin.MouseEnter
        Me.loadDuLieu()
    End Sub

    Private Sub KetoantienmatIUltraGrid_DanhSach_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles KetoantienmatIUltraGrid_DanhSach.MouseEnter
        Me.loadDuLieu()
    End Sub

    Private Sub ThongTinChinh_TimKiemIUltraGrid_ClickCell(sender As Object, e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles ThongTinChinh_TimKiemIUltraGrid.ClickCell
        Try
            Me.KetoannganhangBindingSource.Position = Me.KetoannganhangBindingSource.Find("ma", Me.ThongTinChinh_TimKiemIUltraGrid.ActiveRow.Cells("ma").Value.ToString)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ThongTinThue_TimKiemIUltraGrid_ClickCell(sender As Object, e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles ThongTinThue_TimKiemIUltraGrid.ClickCell
        Try
            Me.KetoannganhangBindingSource.Position = Me.KetoannganhangBindingSource.Find("ma", Me.ThongTinThue_TimKiemIUltraGrid.ActiveRow.Cells("ma").Value.ToString)
        Catch ex As Exception

        End Try
    End Sub
End Class